<?php

class Submenu implements IObject {

    private $IDSubmenu;
    private $IDMenu;
    private $IDControleAcao;
    private $StNome;
    private $ItSubitem;
    private $StController;
    private $StAction;

    private $ArSubitens;

    public function __construct($ArSubmenuData) {
        $this->IDSubmenu = $ArSubmenuData['IDSubmenu'];
        $this->IDMenu = $ArSubmenuData['IDMenu'];
        $this->IDControleAcao = $ArSubmenuData['IDControleAcao'];
        $this->StNome = $ArSubmenuData['StNome'];
        $this->ItSubitem = $ArSubmenuData['ItSubitem'];
        $this->StController = $ArSubmenuData['StController'];
        $this->StAction = $ArSubmenuData['StAction'];

        $this->ArSubmenus = array();
    }

    public function has($Controller, $Action) {
        if( !empty($this->ArSubitens) ) {
            if( $this->isGroup() ) {
                foreach( $this->ArSubitens as $SubmenuItem ) {
                    if( $SubmenuItem->hasUrl($Controller, $Action) ) {
                        return true;
                    }
                    continue;
                }
            }
            if( $this->hasUrl($Controller, $Action) ) {
                return true;
            }
        }
        return false;
    }

    public function hasUrl($StController, $StAction) {
        return DRA_URL . $StController . '/' . $StAction == $this->getStUrl();
    }

    public function isSubitem() {
        return !empty($this->ItSubitem);
    }

    public function isGroup() {
        return empty($this->StController) && empty($this->StAction);
    }

    public function hasSubItens() {
        return !empty($this->ArSubitens);
    }

    public function addSubitem($Subitem) {
        $this->ArSubitens[] = $Subitem;
    }

    public function getIDMenu() {
        return $this->IDMenu;
    }

    public function getIDSubmenu() {
        return $this->IDSubmenu;
    }

    public function getStUrl() {
        return !empty($this->StController) && !empty($this->StAction) ? DRA_URL . $this->StController . '/' . $this->StAction : '';
    }

    public function getStNome() {
        return $this->StNome;
    }

    public function getItSubitem() {
        return $this->ItSubitem;
    }

    public function getArSubitens() {
        return $this->ArSubitens;
    }

    public function getStController() {
        return $this->StController;
    }

    public function getStAction() {
        return $this->StAction;
    }

    public function equals(IObject $Object) {

    }
}

?>
